package com.xbongbong.saas.analytical.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.PaasFormEntity;
import com.xbongbong.paas.enums.PaySheetTypeEnum;
import com.xbongbong.paas.help.CommonHelp;
import com.xbongbong.paas.help.team.TeamUserHelp;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.pojo.dto.AddBatchDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateGetDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.Arith;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.pro.constant.BusinessConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.domain.entity.FormConfigEntity;
import com.xbongbong.pro.enums.ReceiveStatusEnum;
import com.xbongbong.pro.enums.errorcodes.PayErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.PurchaseErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formdata.pojo.SaasNeedRedundantAttrPojo;
import com.xbongbong.saas.analytical.SaasValidateAnalyticalService;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.entity.SupplierProductEntity;
import com.xbongbong.saas.enums.FormConfigEnum;
import com.xbongbong.saas.enums.InstockTypeEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.PayPlanEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.help.AnalyticalHelp;
import com.xbongbong.saas.help.SaasDataInitHelp;
import com.xbongbong.saas.help.SaasProductHelp;
import com.xbongbong.saas.help.SaveFormatHelp;
import com.xbongbong.saas.model.FormConfigModel;
import com.xbongbong.saas.model.SupplierProductModel;
import com.xbongbong.saas.service.toolbox.help.FundMoneyHelp;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import com.xbongbong.util.ProductUtil;
import com.xbongbong.util.PurchaseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static com.xbongbong.saas.toolbox.help.FastJsonHelper.getDoubleOrDefaultFromFormData;
import static com.xbongbong.saas.toolbox.help.FastJsonHelper.getIntegerOrDefaultFromFormData;

/**
 * @author 吴峰
 * @date 2021/07/15 17:15
 */
@Service("purchaseAnalyticalServiceImpl")
public class PurchaseValidateAnalyticalServiceImpl implements SaasValidateAnalyticalService {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseValidateAnalyticalServiceImpl.class);


    @Resource
    private CommonHelp commonHelp;
    @Resource
    private FundMoneyHelp fundMoneyHelp;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private PayPlanSheetValidateAnalyticalServiceImpl payPlanSheetAnalyticalService;
    @Resource
    private PayPlanValidateAnalyticalServiceImpl payPlanAnalyticalService;
    @Resource
    private FormConfigModel formConfigModel;
    @Resource
    private SupplierProductModel supplierProductModel;
    @Resource
    private SaasProductHelp saasProductHelp;
    @Resource
    private TeamUserHelp teamUserHelp;
    @Resource
    private AnalyticalHelp analyticalHelp;

    @Override
    public List<Integer> type() {
        return Arrays.asList(XbbRefTypeEnum.PURCHASE.getCode());
    }

    @Override
    public void analyticalData(ValidateDataDTO validateDataDTO) throws XbbException {
        beforeSave(validateDataDTO);
        teamUserHelp.beforeVerifyUserTeam(validateDataDTO);
    }
    
    public void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException {
        try {
            JSONObject data = validateDataDTO.getData();
            String corpid = validateDataDTO.getCorpid();
            Long dataId = validateDataDTO.getDataId();
            Long taskId = validateDataDTO.getTaskId();
            // 特殊字段数据格式化
            SaveFormatHelp.formatLinkBusiness4Save(data, PurchaseEnum.SUPPLIER_ID.getAttr(), PurchaseEnum.SUPPLIER_ID_LINKED_TEXT.getAttr(), PurchaseEnum.SUPPLIER_ID.getFieldType());
            boolean isNew = analyticalHelp.isNew(validateDataDTO.getDataId(), validateDataDTO.getTaskId(), validateDataDTO.getCorpid());
            Double amount = getDoubleOrDefaultFromFormData(data, PurchaseEnum.TOTAL_MONEY.getAttr(), 0D);
            if (isNew) {
                data.put(PurchaseEnum.UN_FINISH_AMOUNT.getAttr(), amount);
                data.put(PurchaseEnum.UN_INVOICE_AMOUNT.getAttr(), amount);
            }
            // 采购合同参数保存前对相关参数进行合理化校验
            PurchaseUtil.parameterCheck(validateDataDTO);

            JSONArray productArray = FastJsonHelper.getJsonArrOrDefaultFromFormData(data,PurchaseEnum.PRODUCT.getAttr(),new JSONArray());
            Long supplierId = data.getLong(PurchaseEnum.SUPPLIER_ID.getAttr());
            Boolean productCanSee = true;
            boolean allIncomingBound = false;
            if (!isNew) {
                productCanSee = commonHelp.attrCanSee(validateDataDTO.getExplainMap().get(PurchaseEnum.PRODUCT.getAttr()),
                        dataId, validateDataDTO.getCreatorId(), validateDataDTO.getLoginUser(), corpid, XbbRefTypeEnum.PURCHASE.getCode());
                if (productCanSee) {
                    // 关联产品字段启用，可见，及高级可见时才校验关联产品
                    allIncomingBound = validateProductDemo(dataId, productArray, validateDataDTO.getCorpid(), supplierId, validateDataDTO.getFormId(), isNew);
                } else {
                    // 不可见就取是否入库完毕原值
                    Integer allIncoming = getIntegerOrDefaultFromFormData(data, PurchaseEnum.ALL_INCOMING.getAttr(), BasicConstant.ONE);
                    allIncomingBound = allIncoming != 0;
                }
                //编辑和新建和编辑进审批时完全分开
                PaasFormDataEntity paasFormDataEntity = validateDataDTO.getPaasFormDataEntity();
                //编辑进审批时，已经走过一遍beforesave了，无需在设置发货状态值
                if (Objects.nonNull(paasFormDataEntity)) {
                    JSONObject oldData = paasFormDataEntity.getData();
                    String receiveStatus = FastJsonHelper.getStringOrDefaultFromFormData(oldData, PurchaseEnum.RECEIVE_STATUS.getAttr(), ReceiveStatusEnum.UNRECEIVED.getCode());
                    if (!Objects.equals(receiveStatus,ReceiveStatusEnum.CLOSED.getCode())) {
                        if (productArray.isEmpty()) {
                            data.put(PurchaseEnum.RECEIVE_STATUS.getAttr(),ReceiveStatusEnum.UNRECEIVED.getCode());
                        } else if (allIncomingBound){
                            data.put(PurchaseEnum.RECEIVE_STATUS.getAttr(),ReceiveStatusEnum.RECEIVED.getCode());
                        } else if (!Objects.equals(receiveStatus,ReceiveStatusEnum.PARTIAL.getCode())){
                            data.put(PurchaseEnum.RECEIVE_STATUS.getAttr(),ReceiveStatusEnum.UNRECEIVED.getCode());
                        }
                    }
                }
                //编辑采购合同，校验一下采购金额和采购合同已开票金额
                double invoiceAmount = FastJsonHelper.getDoubleOrDefaultFromFormData(data, PurchaseEnum.INVOICE_AMOUNT.getAttr(), 0d);
                if (invoiceAmount > amount) {
                    throw new XbbException(PurchaseErrorCodeEnum.API_ERROR_225039);
                }
            } else {
                allIncomingBound = validateProductDemo(dataId, productArray, validateDataDTO.getCorpid(), supplierId, validateDataDTO.getFormId(), isNew);
                //新建
                data.put(PurchaseEnum.RECEIVE_STATUS.getAttr(), ReceiveStatusEnum.UNRECEIVED.getCode());
            }
            data.put(PurchaseEnum.ALL_INCOMING.getAttr(), allIncomingBound ? 1 : 0);
            Double payTotalAmount = 0D;
            SaasNeedRedundantAttrPojo pojo = new SaasNeedRedundantAttrPojo();
            // TODO 付款计划
            List<Long> payPlanFlowStatusIdList = new ArrayList<>();
            JSONArray payPlanArray = FastJsonHelper.getJsonArrFromFormData(data, PurchaseEnum.ADD_PAYPLAN.getAttr());
            PurchaseUtil.getFlowStatusIdList(validateDataDTO, payPlanArray, payPlanFlowStatusIdList);
            boolean fromApproval = Objects.nonNull(validateDataDTO.getTaskId());
            if (payPlanArray != null && !payPlanArray.isEmpty()) {
                PaasFormEntity paymentFormEntity = paasFormModel.getByBusinessType(XbbRefTypeEnum.PAY_PLAN.getCode(),corpid);
                FormDataAddDTO formDataAddDTO = new FormDataAddDTO();
                BeanUtil.copyProperties(validateDataDTO,formDataAddDTO);
                formDataAddDTO.setAppId(paymentFormEntity.getAppId());
                formDataAddDTO.setMenuId(paymentFormEntity.getMenuId());
                formDataAddDTO.setFormId(paymentFormEntity.getId());
                JSONObject payPlanData = new JSONObject();
                JSONObject supplierData = new JSONObject();
                supplierData.put(StringConstant.SAAS_LINK_BUSINESS_ID,data.getString(PurchaseEnum.SUPPLIER_ID.getAttr()));
                supplierData.put(StringConstant.SAAS_LINK_BUSINESS_NAME,data.getString(PurchaseEnum.SUPPLIER_ID_LINKED_TEXT.getAttr()));
                JSONObject purchaseData = new JSONObject();
                purchaseData.put(StringConstant.SAAS_LINK_BUSINESS_ID,dataId == null ? "0" : dataId);
                purchaseData.put(StringConstant.SAAS_LINK_BUSINESS_NAME, formDataAddDTO.getSerialNo());
                payPlanData.put(PayPlanEnum.LINK_SUPPLIER.getAttr(), Collections.singletonList(supplierData));
                payPlanData.put(PayPlanEnum.LINK_PURCHASE.getAttr(),Collections.singletonList(purchaseData));
                payPlanData.put(PayPlanEnum.ADD_PAYPLAN.getAttr(),payPlanArray);
                formDataAddDTO.setDataList(payPlanData);
                formDataAddDTO.getSaasNeedRedundantAttrPoJo().setParentBusinessType(formDataAddDTO.getBusinessType());
                formDataAddDTO.getSaasNeedRedundantAttrPoJo().setParentAmount(data.getDouble(PurchaseEnum.TOTAL_MONEY.getAttr()));
                formDataAddDTO.setIsTotalPaymentSheetAmount(false);
                formDataAddDTO.setBusinessType(XbbRefTypeEnum.PAY_PLAN.getCode());
                AddBatchDTO addBatchDTO = payPlanAnalyticalService.beforeSaveBatch(formDataAddDTO, fromApproval);
                payTotalAmount = Arith.add(payTotalAmount, addBatchDTO.getAmount());
                data.put(PurchaseEnum.ADD_PAYPLAN.getAttr(), payPlanArray);
                pojo.setAddBatchDTO(addBatchDTO);
            }
            List<Long> paySheetFlowStatusIdList = new ArrayList<>();
            List<Long> writeOffPrepayStatusIdList = new ArrayList<>();
            JSONArray writeOffPrepayArray = FastJsonHelper.getJsonArrFromFormData(data, PurchaseEnum.ADD_WRITE_OFF_PREPAY.getAttr());
            JSONArray paySheetArray = FastJsonHelper.getJsonArrFromFormData(data, PurchaseEnum.ADD_PAY_SHEET.getAttr());
            PurchaseUtil.getFlowStatusIdList(validateDataDTO, writeOffPrepayArray, writeOffPrepayStatusIdList);
            PurchaseUtil.getFlowStatusIdList(validateDataDTO, paySheetArray, paySheetFlowStatusIdList);
            if ( CollectionsUtil.isNotEmpty(writeOffPrepayArray) || CollectionsUtil.isNotEmpty(paySheetArray)) {
                PaasFormEntity paySheetFormEntity = paasFormModel.getByBusinessType(XbbRefTypeEnum.PAY_SHEET.getCode(),corpid);
                FormDataAddDTO formDataAddDTO = new FormDataAddDTO();
                BeanUtil.copyProperties(validateDataDTO,formDataAddDTO);
                formDataAddDTO.setAppId(paySheetFormEntity.getAppId());
                formDataAddDTO.setMenuId(paySheetFormEntity.getMenuId());
                formDataAddDTO.setFormId(paySheetFormEntity.getId());
                JSONObject paySheetData = new JSONObject();
                JSONObject supplierData = new JSONObject();
                supplierData.put(StringConstant.SAAS_LINK_BUSINESS_ID,data.getString(PurchaseEnum.SUPPLIER_ID.getAttr()));
                supplierData.put(StringConstant.SAAS_LINK_BUSINESS_NAME,data.getString(PurchaseEnum.SUPPLIER_ID_LINKED_TEXT.getAttr()));
                JSONObject purchaseData = new JSONObject();
                purchaseData.put(StringConstant.SAAS_LINK_BUSINESS_ID,dataId == null ? "0" : dataId);
                purchaseData.put(StringConstant.SAAS_LINK_BUSINESS_NAME, formDataAddDTO.getSerialNo());
                paySheetData.put(PaySheetEnum.LINK_SUPPLIER.getAttr(),Collections.singletonList(supplierData));
                paySheetData.put(PaySheetEnum.LINK_PURCHASE.getAttr(),Collections.singletonList(purchaseData));
                if ( CollectionsUtil.isNotEmpty(paySheetArray) ) {
                    paySheetData.put(PurchaseEnum.ADD_PAY_SHEET.getAttr(),paySheetArray);
                    formDataAddDTO.setDataList(paySheetData);
                    formDataAddDTO.getSaasNeedRedundantAttrPoJo().setParentBusinessType(validateDataDTO.getBusinessType());
                    formDataAddDTO.getSaasNeedRedundantAttrPoJo().setParentAmount(data.getDouble(PurchaseEnum.TOTAL_MONEY.getAttr()));
                    formDataAddDTO.setBusinessType(XbbRefTypeEnum.PAY_SHEET.getCode());
                    AddBatchDTO addPaySheetBatchDTO = payPlanSheetAnalyticalService.beforeSaveBatch(formDataAddDTO, PaySheetTypeEnum.WRITE_OFF_PAY,data.getLongValue(PurchaseEnum.SUPPLIER_ID.getAttr()), fromApproval);
                    payTotalAmount = Arith.add(payTotalAmount, addPaySheetBatchDTO.getAmount());
                    data.put(PurchaseEnum.ADD_PAY_SHEET.getAttr(), paySheetArray);
                    pojo.setAddPaymentSheetBatchDTO(addPaySheetBatchDTO);
                }
                if ( CollectionsUtil.isNotEmpty(writeOffPrepayArray) ) {
                    paySheetData.put(PurchaseEnum.ADD_WRITE_OFF_PREPAY.getAttr(),writeOffPrepayArray);
                    formDataAddDTO.setDataList(paySheetData);
                    formDataAddDTO.getSaasNeedRedundantAttrPoJo().setParentBusinessType(validateDataDTO.getBusinessType());
                    formDataAddDTO.getSaasNeedRedundantAttrPoJo().setParentAmount(data.getDouble(PurchaseEnum.TOTAL_MONEY.getAttr()));
                    formDataAddDTO.setBusinessType(XbbRefTypeEnum.WRITE_OFF_PREPAY.getCode());
                    AddBatchDTO addWriteOffPrepayBatchDTO = payPlanSheetAnalyticalService.beforeSaveBatch(formDataAddDTO, PaySheetTypeEnum.WRITE_OFF_PREPAY,data.getLongValue(PurchaseEnum.SUPPLIER_ID.getAttr()), fromApproval);
                    payTotalAmount = Arith.add(payTotalAmount, addWriteOffPrepayBatchDTO.getAmount());
                    data.put(PurchaseEnum.ADD_WRITE_OFF_PREPAY.getAttr(), writeOffPrepayArray);
                    pojo.setAddWriteOffPrepaymentBatchDTO(addWriteOffPrepayBatchDTO);
                }
            }
            validateDataDTO.setSaasNeedRedundantAttrPoJo(pojo);
            //查出这条合同相关的坏账与红冲金额
            if ( !isNew ) {
                FormDataUpdateGetDTO formDataUpdateGetDTO = new FormDataUpdateGetDTO();
                BeanUtil.copyProperties(validateDataDTO, formDataUpdateGetDTO);
                LOGGER.info("amount:"+amount+ "统计后的金额payTotalAmount：" +payTotalAmount);
                payTotalAmount = fundMoneyHelp.getImportCoverCalAmount(payTotalAmount,formDataUpdateGetDTO,validateDataDTO.getExplainMap(),XbbRefTypeEnum.PURCHASE.getCode(),validateDataDTO.getIsImport(),
                        payPlanFlowStatusIdList, paySheetFlowStatusIdList,writeOffPrepayStatusIdList);
                LOGGER.info("统计后的金额payTotalAmount：" +payTotalAmount);
            }
            if (payTotalAmount > amount){
                LOGGER.info("统计后的金额payTotalAmount：" +payTotalAmount+",与采购合同金额：amount:"+amount);
                throw new XbbException(PurchaseErrorCodeEnum.API_ERROR_225033);
            }
            if ( !Objects.equals(validateDataDTO.getIsImport(), 1) ) {
                FormConfigEntity formConfig = formConfigModel.getEntityByFormId(validateDataDTO.getCorpid(), validateDataDTO.getFormId(), FormConfigEnum.PURCHASE_AMOUNT_EQUAL_PAYMENT_PLAN.getConfig());
                boolean isPurchaseAmountEqualPayment = Objects.equals(FormConfigEnum.PURCHASE_AMOUNT_EQUAL_PAYMENT_PLAN.getConfigValue(), StringConstant.POSITIVE_NUMBER);
                if ( Objects.nonNull(formConfig) ) {
                    if ( Objects.equals(formConfig.getConfigValue(), StringConstant.POSITIVE_NUMBER) ) {
                        isPurchaseAmountEqualPayment = true;
                    } else {
                        isPurchaseAmountEqualPayment = false;
                    }
                }
                if ( isPurchaseAmountEqualPayment ) {
                    if ( !Objects.equals(payTotalAmount, amount) ) {
                        throw new XbbException(PayErrorCodeEnum.API_ERROR_226011);
                    }
                }
            }
            // 各种利润信息在前面先算
            PurchaseUtil.calculatePurchaseCost(validateDataDTO, isNew);
            for (Map.Entry<String,Object> entry : SaasDataInitHelp.initPurchase().entrySet()){
                SaasDataInitHelp.antDataSet(data,entry.getKey(),entry.getValue());
            }
            validateDataDTO.setData(data);
            Map<String,Boolean> attrCanSeeMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            attrCanSeeMap.put(PurchaseEnum.PRODUCT.getAttr(),productCanSee);
            validateDataDTO.getSaasNeedRedundantAttrPoJo().setAttrCanSeeMap(attrCanSeeMap);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOGGER.error("purchaseAnalyticalServiceImpl.beforeSave error", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
    }


    /**
     * 供应商产品校验
     * @param purchaseId
     * @param productList
     * @param corpid
     * @param supplierId
     * @return
     * @throws XbbException
     */
    private boolean validateProductDemo(Long purchaseId, JSONArray productList, String corpid, Long supplierId, Long formId, boolean isNew) throws XbbException {
        if (isNew && (Objects.isNull(productList) || productList.isEmpty())){
            return true;
        }
        Set<Long> pageProductIds = new HashSet<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        for (Object obj : productList){
            JSONObject json = JSONObject.parseObject(obj.toString());
            Long productId = json.getLong(SelectProductEnum.PRODUCT.getAttr());
            pageProductIds.add(productId);
        }
        //判断产品合法
        Map<Long,String> pageProductMap = saasProductHelp.productExitContract(productList,corpid,new ArrayList<>(pageProductIds));

        // 避免导入时导入非此供应商的关联产品
        boolean isPurchaseProductMustBelongSupplier = false;
        FormConfigEntity formConfigEntity = formConfigModel.getEntityByFormId(corpid, formId, FormConfigEnum.PURCHASE_PRODUCT_MUST_BELONG_SUPPLIER.getConfig());
        if (Objects.isNull(formConfigEntity)){
            isPurchaseProductMustBelongSupplier = Objects.equals(FormConfigEnum.PURCHASE_PRODUCT_MUST_BELONG_SUPPLIER.getConfigValue(),BasicConstant.IS_USE.toString());
        } else if (Objects.equals(formConfigEntity.getConfigValue(), BasicConstant.IS_USE.toString())) {
            isPurchaseProductMustBelongSupplier = true;
        }
        if (isPurchaseProductMustBelongSupplier) {
            Map<String,Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put("corpid",corpid);
            param.put("del",0);
            param.put("supplierId",supplierId);
            param.put("productIdIn",pageProductIds);
            List<SupplierProductEntity> supplierProductEntityList = supplierProductModel.findEntitys(param);
            supplierProductEntityList.forEach(item -> pageProductIds.remove(item.getProductId()));
            if (!pageProductIds.isEmpty()){
                throw new XbbException(PurchaseErrorCodeEnum.API_ERROR_225022);
            }
        }

        boolean allIncoming = false;
        if (!isNew) {
            // 获取下游采购入库单的产品
            Map<String, Double> businessProductMap = saasProductHelp.getInstockProduct(corpid, purchaseId, InstockTypeEnum.PURCHASE_INSTOCK.getCode(), pageProductMap);
            boolean haveCorresponding = false;
            for (String s : businessProductMap.keySet()) {
                if (s.contains("_")) {
                    haveCorresponding = true;
                    break;
                }
            }
            boolean needMerge = !businessProductMap.isEmpty() && !haveCorresponding;
            Map<String, Double> productNumMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            for (Object obj : productList) {
                JSONObject json = (JSONObject) obj;
                Long productId = json.getLong(SelectProductEnum.PRODUCT.getAttr());
                // PRODUCT_SUB_ID是编辑的时候传给前段的采购合同产品的主键id，保存的时候前端传回来！！
                Long productSubId = json.getLong(BusinessConstant.PRODUCT_SUB_ID);
                String key;
                if (needMerge) {
                    key = productId.toString();
                } else {
                    key = productId + "_" + productSubId;
                }
                Double productNum = json.getDouble(SelectProductEnum.NUM.getAttr());
                Double num = productNumMap.getOrDefault(key, 0D);
                num = Arith.add(num, productNum);
                productNumMap.put(key, num);
            }
            allIncoming = ProductUtil.upstreamDocumentsProductNumLegalCheck(false, businessProductMap, productNumMap, pageProductMap, I18nMessageUtil.getMessage(I18nStringConstant.LESS_STOCK_NUM));
        }
        return allIncoming;
    }

    
}
